"""
Flask + Flask-SQLAlchemy + PostgreSQL + Layui 表格数据展示方案
"""
import click

from tzq.extensions import db
from tzq.flask_sqlalchemy_postgresql_layui.fspl_models import User


def register_fspl_commands(app):
    @app.cli.command("forge_fspl")
    def forge():
        """fspl Generate fake data."""
        if not User.query.first():
            users = [
                User(username='admin', email='admin@example.com', role='admin'),
                User(username='user1', email='user1@example.com'),
                User(username='user2', email='user2@example.com'),
                User(username='user3', email='user3@example.com'),
            ]
            db.session.bulk_save_objects(users)
            db.session.commit()
        click.echo('data initialize Done.')
